<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;

class PublicController extends Controller
{
    /**
     *  登录页
     */
    public function login()
    {
        return view('admin/public/login');
    }
    /**
     * 验证数据
     */
    public function check(Request $request)
    {
        $this->validate($request,[
            'username' => 'required|min:2|max:20',
            'password' => 'required|min:6',
            'captcha' => 'required|size:4|captcha'
        ]);
        $data = $request->only(['username','password']);
        $data['status'] = 2;
        $result = Auth::guard('admin')->attempt($data,$request->get('online'));
        if($result){
            return redirect('/admin/index/index');
        }else {
            return redirect('/admin/public/login')->withErrors([
                'loginError' => '用户名或密码错误。'
            ]);
        }
    }
    /**
     * 退出登录
     */
    public function logout()
    {
        Auth::guard('admin')->logout();
        return redirect('/admin/public/login');
    }
}
